<!DOCTYPE html>
<html lang="en">

	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8">
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
		<meta name="description" content="">
		<meta name="author" content="">
		<!-- STYLESHEETS -->
		<!--[if lt IE 9]><script src="../../js/flot/excanvas.min.js"></script><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script><![endif]-->
    <link rel="stylesheet" type="text/css" href="../../css/cloud-admin.css" >
	<link rel="stylesheet" type="text/css"  href="../../css/themes/default.css" id="skin-switcher" >
	<link rel="stylesheet" type="text/css"  href="../../css/responsive.css" >	
	<link href="../../font-awesome/css/font-awesome.min.css" rel="stylesheet">
	<!-- SELECT2 -->
	<link rel="stylesheet" type="text/css" href="../../js/select2/select2.min.css" />
	<!-- UNIFORM -->
	<link rel="stylesheet" type="text/css" href="../../js/uniform/css/uniform.default.min.css" />
	<!-- datatable -->
    <link rel="stylesheet" href="../../js/datatables/datatable.css">
    <link rel="stylesheet" href="../../js/datepicker/datepicker.css">
       <link rel="stylesheet" type="text/css" href="../../js/file-input/fileinput.css"/>
  <script src="../../js/jquery/jquery-2.0.3.min.js"></script>
    <script src="../../js/common.js"></script>
	</head>

	<body>
		<header class="navbar clearfix" id="header">
		</header>

		<!-- PAGE -->
		<section id="page">
			<!-- SIDEBAR -->
			<div id="sidebar" class="sidebar">
				<div class="sidebar-menu nav-collapse">

					<!-- SIDEBAR MENU -->
					<ul>
						
					</ul>
					<!-- /SIDEBAR MENU -->
				</div>

			</div>
			<!-- /SIDEBAR -->
			<div id="main-content">

				<div class="container">
					<div class="row">
						<div id="content" class="col-lg-12">
							<!-- PAGE HEADER-->
							<div class="row">
								<div class="col-sm-12">
									<div class="page-header">
										<!-- STYLER -->

										<!-- /STYLER -->
										<!-- BREADCRUMBS -->
										<ul class="breadcrumb">
											<li>
												<i class="fa fa-home"></i>
												<a href="index.html">首页</a>
											</li>
											<li>
												<a href="#">商品管理</a>
											</li>
											<li>维护商品</li>
										</ul>
										<!-- /BREADCRUMBS -->

									</div>
								</div>
							</div>
							<!-- /PAGE HEADER -->
							<!-- SAMPLE -->
							
							<div class="row col-md-12">
								
							<form id="form_invoice">
								<input type="hidden" name="id"/>
								<input type="hidden" name="supplierId"/>
								<input type="hidden" name="rateType" value="VAT"/>
								<div class="form-group  mrg-bt10 frameCode" style="display:none">
											<label class="control-label col-md-3"><span class="required">*</span>框架协议号：</label>
											<div class="col-md-9" style="text-align: left;display: inline-flex">
												<input type="text" class="form-control"  style="width: 36%" name="frameCode" value="" maxlength="20" />										
											</div>

								</div>
								
								<div class="form-group  mrg-bt10">
									<label class="control-label col-md-3" style="line-height:34px;">供应商名称：</label>
									<div class="col-md-9" style="display: inline-flex" id="supplierName">
										
									</div>
								</div>
								<div class="form-group  mrg-bt10">
											<label class="control-label col-md-3"><span class="required">*</span>发票类型：</label>
											<div class="col-md-9" style="text-align: left;display: inline-flex">
												增值税专用发票
											</div>

								</div>
								<div class="form-group  mrg-bt10" >
											<label class="control-label col-md-3"><span class="required">*</span>税率：</label>
											<div class="col-md-9" style="text-align: left;display: inline-flex">
												<input type="text" class="form-control"  style="width: 10%" name="rate" placeholder="税率" onkeypress="return $.IsNum(event);" onblur="return $.IsNaN(this);" maxlength="10" />%(只输入数字,如17)										
											</div>

								</div>
								<div class="form-group  mrg-bt10">
											<label class="control-label col-md-3"><span class="required">*</span>框架有效期：</label>
											<div class="col-md-4" style="text-align: left;display: inline-flex">
											
													<div class="col-sm-2" style="width:130px;margin-left:-14px" >
														 <input type="text" name="startDate"  class="form-control bootstrap-datepicker">
													</div>
													<div style="width: 20px">至</div>
														<div class="float-left" style="width:130px">
															 <input type="text" name="endDate" class="form-control bootstrap-datepicker">
														</div>	
												
											</div>

								</div>
								<div class="form-group  mrg-bt10">
											<label class="control-label col-md-3"><span class="required">*</span>短溢比例 ：</label>
											<div class="col-md-9" style="text-align: left;display: inline-flex">下限
												<input type="text" class="form-control"  style="width: 10%" name="minOverflow" onkeypress="return $.IsNum(event);" onblur="return $.IsNaN(this);" placeholder="下限" maxlength="10" value="3" />	
												<div style="width: 30px">% </div>上限
												<input type="text" class="form-control"  style="width: 10%" name="maxOverflow" onkeypress="return $.IsNum(event);" onblur="return $.IsNaN(this);" placeholder="上限" maxlength="10" value="3" />%																			
											</div>

								</div>
								<div class="form-group  mrg-bt10">
											<label class="control-label col-md-3">备注：</label>
											<div class="col-md-9" style="text-align: left;display: inline-flex">
												<input type="text" class="form-control" style="width: 36%" name="remark" placeholder="备注" maxlength="100"/>												
											</div>

								</div>
								
														
							</form>
							
								
								<div class="row" style="height: 30px;">
								<div class="col-md-10" style="text-align: center;">
									<div class="box ">
										<a href="javascript:;"  class="btn btn-success config bt-submit" style="width: 100px;margin-top:20px;">
											保存
										</a>										
										<a href="javascript:history.go(-1);"  class="btn btn-default" style="width: 100px;margin-top:20px;">
											取消并返回
										</a>
									</div>
								</div>
					    </div>			
						
							<!-- /SAMPLE -->

							<div class="footer-tools">
								<span class="go-top">
								<i class="fa fa-chevron-up"></i> Top
							</span>
							</div>
						</div>
						<!-- /CONTENT-->
					</div>
				</div>
			</div>
		</section>
		<!--/PAGE -->
		<!-- JAVASCRIPTS -->
		<!-- Placed at the end of the document so the pages load faster -->

		
	
	<!-- JQUERY -->
<script src="../../js/jquery/jquery-2.0.3.min.js"></script>
<script src="../../js/common.js"></script>
<!-- JQUERY UI-->
<script src="../../js/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.min.js"></script>
<!-- BOOTSTRAP -->
<script src="../../bootstrap-dist/js/bootstrap.min.js"></script>
<!-- SLIMSCROLL -->
<script type="text/javascript" src="../../js/jQuery-slimScroll-1.3.0/jquery.slimscroll.min.js"></script>
<script type="text/javascript" src="../../js/jQuery-slimScroll-1.3.0/slimScrollHorizontal.min.js"></script>
<!-- BLOCK UI -->
<script type="text/javascript" src="../../js/jQuery-BlockUI/jquery.blockUI.min.js"></script>
<!--bootbox-->
<script type="text/javascript" src="../../js/bootbox/bootbox.min.js"></script>
<!-- AUTOSIZE -->
<script type="text/javascript" src="../../js/autosize/jquery.autosize.min.js"></script>
<!-- spinner -->
<script src="../../js/spinner/spin.js"></script>
<!-- bootstrap-fileupload -->
<script type="text/javascript" src="../../js/jquery-upload/js/jquery.iframe-transport.js"></script>
<script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload.min.js"></script>
<script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload-process.min.js"></script>
<script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload-validate.min.js"></script>

<!-- INPUT MASK -->
<script type="text/javascript" src="../../js/bootstrap-inputmask/bootstrap-inputmask.min.js"></script>

<!-- SELECT2 -->
<script type="text/javascript" src="../../js/select2/select2.min.js"></script>
<!-- UNIFORM -->
<script type="text/javascript" src="../../js/uniform/jquery.uniform.min.js"></script>
<!-- WIZARD -->
<script src="../../js/bootstrap-wizard/jquery.bootstrap.wizard.min.js"></script>
<!-- WIZARD -->
<script src="../../js/jquery-validate/jquery.validate.min.js"></script>
<script src="../../js/jquery-validate/additional-methods.min.js"></script>
<script src="../../js/bootstrap-wizard/form-wizard.js"></script>
<script type="text/javascript" src="../../js/datepicker/datepicker.js"></script>
<!-- NESTABLE LISTS -->
<script type="text/javascript" src="../../js/nestable/jquery.nestable.min.js"></script>
<!-- COOKIE -->
<script type="text/javascript" src="../../js/jQuery-Cookie/jquery.cookie.min.js"></script>
<!-- CUSTOM SCRIPT -->
<script src="../../js/script.js"></script>

<script src="../../js/Sortable.min.js"></script>

<!-- DATA TABLES -->
<script type="text/javascript" src="../../js/datatables/bootstrap-select.js"></script>
<script type="text/javascript" src="../../js/datatables/datatable.js"></script>
<script type="text/javascript" src="../../js/datatables/datatable-bootstrap.js"></script>
<script type="text/javascript" src="../../js/datatables/datatable-tabletools.js"></script>
<script type="text/javascript" src="../../js/datatables/fnAddTr.js"></script>
	
   
		<script>
		
		var Source=function(){
	       
	        var id=null,flag=null,supplierName,supplierId;
	        var valiFrom=$("#form_invoice");
	        var formValiInit=function(){
	            valiFrom.validate({
	                doNotHideMessage: true,
					errorClass: 'error-span',
	                errorElement: 'span',
	                rules: {                	 
	                	minOverflow:{required:true},
	                	maxOverflow:{required:true},
	                	rate:{required:true},
	                	startDate:{required:true},	                	
	                	endDate:{required:true}
	                	
	                },
	                highlight: function (element) { 
	                    $(element).closest('.form-group').removeClass('has-success').addClass('has-error'); 
	                },
	
	                unhighlight: function (element) { 
	                    $(element).closest('.form-group').removeClass('has-error'); 
	                },	
	                success: function (label) {
	                   label.addClass('valid').closest('.form-group').removeClass('has-error').addClass('has-success'); 
	                    }
	               
				 });
			};
	        var getFrame=function(){	          
	           $.ajax({
						type: "get",
						url: App.getContextPath()+"admin/frame/findDetailById.do",
						async: true,
						data: {id:id},
						success: function(result) {
							if(result!=null){
							$("[name=id]").val(result.id);
							$("[name=supplierId]").val(result.supplierId);
				        	$("#supplierName").html(result.supplierName);				        	
				        	$("[name=frameCode]").val(result.frameCode);				        	
				        	$("[name=minOverflow]").val(result.minOverflow);
				        	$("[name=maxOverflow]").val(result.maxOverflow);
				        	$("[name=rate]").val(result.rate);
				        	$("[name=startDate]").val($.getLocalDate(result.startDate));
				        	$("[name=endDate]").val($.getLocalDate(result.endDate));
				        	$("[name=remark]").val(result.remark);
				        	
				        	if(flag=="check"){
			        			$("input").attr("readonly","readonly");
			        			$(".bt-submit").html("归档")
			        			$(".frameCode").show();
			        			$(".frameCode").find("input").removeAttr("readonly");
			        		}
				        	if(flag=="detail"){
				        		$(".btn-success").hide();
				        		$("input").attr("readonly","readonly");
				        		}
				        	
							}
							 
					     }
					   });
	        };
	        var isExistsInvoice=function(){
	        	var isExist=false;
	            $.ajax({
						type: "get",
						url: App.getContextPath()+"admin/frame/isExistsFrame.do",
						async: false,
						data: {frameCode:$("[name=frameCode]").val(),id:id},
						success: function(result) {
							if(result==true)
							{
							   $.alert("框架协议号已经存在");
							   isExist=true;
							}
					     }
					   });
					return isExist;
	        };	      
	        //保存渠道
	        var saveInvoice=function(){	       
	        	if(valiFrom.valid() == false)return false;
	        	if(flag=="check"&&isExistsInvoice())
	        	 return false;
	        	var invoiceJson=$("#form_invoice").serializeObject();
	        	if(id!=null&&flag=="check"){
	        		if(invoiceJson.frameCode==""){
	        			$.alert("请输入框架协议号");
	        			return false;
	        		}
	        	}
	        	$.blockUI();
	        	
	        	
	        	if(flag=="check")invoiceJson.frameStatus="Archived";
	        	$.confirm("确认保存框架协议?",function(){
	        		$.ajax({
						type: "post",
						url: App.getContextPath()+"admin/frame/saveFrame.do",
						async: true,
						data: $.param({frame:JSON.stringify(invoiceJson)}),
						success: function(result) {
							$.unblockUI();
							if(result.type=="success")
								window.history.go(-1);
					     }
					   });
	        		
	        	});
	        	
	        
	        };
	        
	       
	         return {	         
		         init:function(){		            
					 formValiInit();
					 $.initDate($("#form_invoice"),0,365);	
					 $(".bt-submit").unbind("click").click(saveInvoice);
		             id=$.getUrlParam("id");
		             flag=$.getUrlParam("flag");
		             $("[name=supplierId]").val($.getUrlParam("supplierid"));
            		 $("#supplierName").html($.getUrlParam("suppliername"));
		             if(id){
		            	 getFrame();
		            	 }
		          }
		    }
	      }();
	      
	      $(function(){
	      	$("#header").load("../head.html");
	        App.init(); //Initialise plugins and elements	        
	      	Source.init();
	      	
	      });
		</script>
	

		<!-- /JAVASCRIPTS -->
	</body>

</html>